  

var mapObj,toolbar,overview,scale,mouseTool;
	function mapInit(){
		var bdLong = document.getElementById("bdLong").value;
		var bdLat = document.getElementById("bdLat").value;
		
		if(bdLong == "" && bdLat == ""){//设置地图中心点(苏州)
			bdLong = 120.58531600000003;
			bdLat = 31.298886;
		}else{//设置地图中心点(门店位置)
		}
		var opt = {
			level:13,//初始地图视野级别
			center:new MMap.LngLat(bdLong,bdLat),	
			doubleClickZoom:true,//双击放大地图
			scrollWheel:true//鼠标滚轮缩放地图
		}
		mapObj = new MMap.Map("map",opt);
		mapObj.plugin(["MMap.ToolBar","MMap.OverView","MMap.Scale","MMap.MouseTool"],function(){ 
			toolbar = new MMap.ToolBar();
			toolbar.autoPosition=false; //加载工具条 
			mapObj.addControl(toolbar);  	
			overview = new MMap.OverView(); //加载鹰眼
			mapObj.addControl(overview);  	
			scale = new MMap.Scale(); //加载比例尺
			mapObj.addControl(scale);
			mouseTool = new MMap.MouseTool(mapObj);
		});
		var bdLongOld = document.getElementById("bdLong").value;
		var bdLatOld = document.getElementById("bdLat").value;
		if(bdLongOld != "" && bdLatOld != ""){
			marker = new MMap.Marker({ 
				id:"oldMapInfo",
				position:new MMap.LngLat(bdLongOld,bdLatOld),
				icon:"http://code.mapabc.com/images/lan_1.png",
				offset:new MMap.Pixel(0,-36),
				draggable:false,
				cursor:"default",
				visible:true
			});
			mapObj.addOverlays(marker);   
			mapObj.setCenter(marker.position);
			inforWindow = new MMap.InfoWindow({   
				content:"影院地址(原)",   
				offset:new MMap.Pixel(-93,-78)   
			});   
			mapObj.bind(marker,"click",function(e){   
				inforWindow.open(mapObj,marker.getPosition());     
			});
		}
		mapObj.bind(mapObj,"click",function(e){
			mouseTool.close(true);
			mouseTool.marker();
			document.getElementById("bdLong").value=e.lnglat.lng;
			document.getElementById("bdLat").value=e.lnglat.lat;	
		});
		
	}
	//******************地图关键字查询
	function keywordSearch(){
	var keywords = document.getElementById("keyword").value;
	var city = document.getElementById("city").value;
	city=city=='全国'?'total':city;
	var PoiSearchOption = {
		srctype:"POI",//数据来源
		type:"",//数据类别
		number:10,//每页数量,默认10
		batch:1,//请求页数，默认1
		range:3000,	//查询范围，默认3000米
		ext:""//扩展字段
	};
	MMap.Conf._server='http://apis.mapabc.com/';
	var MSearch = new MMap.PoiSearch(PoiSearchOption);
	MSearch.byKeywords(keywords,city,searchPoilist_CallBack);
	}
	var markers=[],infos=[];
	function searchPoilist_CallBack(data){
		mapObj.clearOverlaysByType('marker');
		mapObj.clearInfoWindow();
		if(data.status=='E0'){
			if(data.bounds){
				var a=data.bounds.split(';');
				if(a.length==2){
					var b=a[0].split(','),c=a[1].split(',');
					mapObj.setBounds(new MMap.Bounds(new MMap.LngLat(b[0],b[1]),new MMap.LngLat(c[0],c[1])));
				}else{//只返回一条数据时
					var d=a[0].split(',')
					mapObj.setCenter(new MMap.LngLat(d[0],d[1]))
				}
				
			}	
			var list='<ul id="poisearchUl">';markers=[];infos=[];
			for(var i=0,l=data.list.length;i<l;i++){
				list+='<li id="li'+i+'">'+(i+1)+'、'+data.list[i].name+'</li>'
				markers.push(new MMap.Marker({
					icon:"http://code.mapabc.com/images/lan_1.png",position:new MMap.LngLat(data.list[i].x,data.list[i].y),id:'marker'+i,offset:new MMap.Pixel(-10,-34)
				}));
				mapObj.addOverlays(markers[i]);
				infos.push(new MMap.InfoWindow({
					content:'<b>'+data.list[i].name+'</b><hr/>'+TipContents(data.list[i].type,data.list[i].address,data.list[i].tel,data.list[i].x,data.list[i].y),autoMove:true
											   }));
				mapObj.bind(markers[i],'click',function(){
					var index=this.obj.id.substring(6)
					infos[index].open(mapObj,this.obj.getPosition())
														})
				}
			list+='</ul>';
		}else if(data.status =="E1"){
	         list = "未查找到任何结果!<br />建议：<br />1.请确保所有字词拼写正确。<br />2.尝试不同的关键字。<br />3.尝试更宽泛的关键字。";	
		}else{
			 list= "错误信息："+data.status+"请对照API Server v2.0.0 简明提示码对照表查找错误类型";
		}
		document.getElementById('result').innerHTML=list;
		var liObj = document.getElementsByTagName('li')
		for (i = liObj.length - 1; i >= 0; i--) {
			liObj[i].onmouseover=function(){
				var num=this.id.substring(2);
				this.style.background='#DDDDDD';
				infos[num].open(mapObj,markers[num].getPosition());
			}
			liObj[i].onmouseout=function(){this.style.background='#FFFFFF';}
		};
	}
	function TipContents(type,address,tel,bdLong,bdLat){
		if (type == "" || type == "undefined" || type == null || type == " undefined" || typeof type == "undefined") {
			type = "暂无";
		}
		if (address == "" || address == "undefined" || address == null || address == " undefined" || typeof address == "undefined") {
			address = "暂无";
		}
		if (tel == "" || tel == "undefined" || tel == null || tel == " undefined" || typeof address == "tel") {
			tel = "暂无";
		}
		var str ="经度：" + bdLong + "<br/>纬度：" + bdLat + "<br/>地址：" + address + "<br/>电话：" + tel + " <br/>类型："+type;
		return str;
	}